import React from 'react';
import ReactDOM from 'react-dom';
import Navv from './nav.jsx';
import '../../static/tero/public_two.less'

import $ from 'jquery'
import u from '../../common.js'

class PublicTwo extends React.Component {
    constructor(props) {
        super(props)
        this.state = {
            names: [u.getStore('gzName')],
            flag: true,
            index: 0,
            search: [{ src: "../../static/image/tou_fifty.png", title: '宋中继' }, { src: "../../static/image/tou_fifty.png", title: '王小筱' }, { src: "../../static/image/tou_fifty.png", title: '鲁达' }, { src: "../../static/image/tou_fifty.png", title: '宋中继' }, { src: "../../static/image/tou_fifty.png", title: '钱度' }, { src: "../../static/image/tou_fifty.png", title: '李四' },],
            base: [],
            block: 0,
            mynumber: 11,
            downLoad: true,
            data: {},
            str1: '',
            str2: '',
            img: [],
            top: '-8px',
        }
    }
    blockContent(index) {
        this.setState({
            block: index
        })
    }
    componentWillMount() {
        this.rendering()
    }
    rendering() {
        let that = this;
        u.detail({ id: this.props.location.search.split('?')[1] }, data => {
            if (data.data.length == 0) return
            let str = data.data[0].content;
            str = str.replace(/<br \/>/g, '').replace(/<vrv-img\/>/g, '')
            let img = data.data[0].img
            let str1 = str.substr(0, str.length / 2 - 1)
            let str2 = str.substr(str.length / 2)
            let arr = img.split('http');
            arr.shift();
            let i = 0;
            for (i; i <= arr.length - 1; i++) {
                arr[i] = 'http' + arr[i]
            }

            that.setState((prevState, props) => ({
                data: data.data[0],
                str1: str1,
                str2: str2,
                img: arr
            }))
        })
    }
    attention() {
        if ($('.span2').is(':hidden')) {
            $('.span2').show()
            $('.span').hide()
        }
    }
    cancel() {
        if ($('.span').is(':hidden')) {
            $('.span').show()
            $('.span2').hide()
        }
    }
    render() {
        return (
            <div className='tero_father'>
                <Navv filter={this.state.names} blockContent={this.blockContent.bind(this)} myname={this.state.myname} mynumber={this.state.mynumber} top={this.state.top} downLoad={this.state.downLoad} />
                <div className='nav_b_left_son_peripheryy'>
                    <div className='span'
                        onClick={() => {
                            this.attention()
                        }}
                    >
                        重点关注
                            </div>
                    <div className='span2'
                        onClick={() => {
                            this.cancel()
                        }}
                    >
                        已关注
                            </div>
                </div>
                <div className='nav_bc nav_bc_two_active' style={{ paddingTop: '20px' }} >
                    <h3>{this.state.data.title || '韩国全面部署2萨德 出动员封锁出动8000名警员封锁道路'}</h3>
                    <div className='nav_bc_title'><span><b>发布人：</b>{this.state.data.author || '艾久萧'}</span><span><b>发布时间：</b>{u.unixTime(this.state.data.addTime) || '2017-03-07 14:41:05'}</span><span><b>转载自：</b>{this.state.data.webSite || '新浪新闻-把酒社区'}</span></div>
                    <p>{this.state.str1}</p>
                    <div className='nav_bc_img' style={{ height: 'auto', padding: this.state.img.length !== 0 ? '30px 60px 0px 60px' : '0' }}>{this.state.img && this.state.img.map((item, index) => {
                        return (<img key={index} src={item} alt="" />)
                    })}</div>
                    <p>{this.state.str2}</p>
                </div>
            </div>
        )
    }
}




export default PublicTwo